//
//  MyController.swift
//  edu
//
//  Created by karlzhou on 15/11/24.
//  Copyright © 2015年 karlzhou. All rights reserved.
//

import UIKit

class MyController: UIViewController,UITableViewDataSource,UITableViewDelegate {
     var tableView: UITableView!
    
    let cellContentIdentier = "cellContentIdentier"
    let cellHeaderIdentier =  "cellHeaderIdentier"
    let cellTitle = ["我的收藏","我的下载","播放记录","设置"]
    let imageName = ["ico_my_favorites","ico_my_download","ico_my_history","ico_my_set" ]

    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView = UITableView(frame: self.view.frame)
        let nib = UINib(nibName: "ProfileContentCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: cellContentIdentier)
        
        let headerNib = UINib(nibName: "ProfileHeaderCell", bundle: nil)
        tableView.registerNib(headerNib, forHeaderFooterViewReuseIdentifier: cellHeaderIdentier)
        tableView.scrollEnabled = false
        self.view.addSubview(self.tableView)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //datasuorce
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellContentIdentier, forIndexPath: indexPath) as? ProfileContentCell
        
        print("current row:\(indexPath.row)")
        
        cell?.icon.image = UIImage(named: imageName[indexPath.row])
        cell?.content.text = cellTitle[indexPath.row]
        return cell!
    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellTitle.count
    }
    
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        let views = NSBundle .mainBundle().loadNibNamed("ProfileHeaderView", owner: ProfileHeaderView.self, options: nil)
        
        let headerView = views[0] as! UIView
       
        return headerView
    }
    
    //cell deletgate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        print("didSelect")
    }
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat{
        return 200
    }
    
    
    /*
    // MARK: - Navigation
    
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    }
    */
    
}
